
function assembleTreeData(data:[],parentField:string,idFiled:string,rootId:string){
    return buildChildren(data,parentField,idFiled,rootId);
}

function buildChildren(data:[],parentField:string,idFiled:string,pId:string,pObject?:any){
    let children:[] = [];
    for(const item of data){
        if(item[parentField] == pId){
            (item as any).pNode = pObject;
           // (item as any).id = item[idFiled];
            children.push(item);
            buildChildren(data,parentField,idFiled,item[idFiled],item);
            if(pObject != undefined){
                pObject.children = children;
            }
        }
    }
    return children;
}

export {assembleTreeData}